//
//  ScreenMinView.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/3/9.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

@objc protocol ScreenMinViewDelegate {
    func screenmin_mouseEntered(with event: NSEvent)
    func screenmin_mouseExited(with event: NSEvent)
    
}

class ScreenMinView: MSView {
    
    weak var delegate:ScreenMinViewDelegate?
    
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func getWidth(_ t:String) -> CGFloat {
        let width = t.ga_width(font: 12)+14+6
        return width
    }
    
    func setupUI() {
        
        self.wantsLayer = true
        self.layer?.backgroundColor = color_gray(40).withAlphaComponent(0.7).cgColor
        
        self.addSubview(title)
        title.snp.makeConstraints { (make) in
            make.height.equalTo(14)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview().offset(6)
        }
        
        self.addSubview(statusView)
        statusView.snp.makeConstraints { (make) in
            make.width.height.equalTo(10)
            make.centerY.equalToSuperview()
            make.right.equalTo(title.snp.left).offset(-3)
        }
        self.statusView.zh_border(radius: 5, borderColor: nil, borderWidth: 0)
    }
    
    
    lazy var title: NSLabel = {
        let lab = NSLabel.label(title: "会议号", textColor: color_gray(255), font: NSFont.systemFont(ofSize: 12))
        return lab
    }()
    
    lazy var statusView: NSView = {
        let view = NSView()
        view.wantsLayer = true
        view.layer?.backgroundColor = NSColor.green.cgColor
        return view
    }()
}

extension ScreenMinView {
    override func mouseEntered(with event: NSEvent) {
        self.delegate?.screenmin_mouseEntered(with: event)
        super.mouseEntered(with: event)
    }
    
    override func mouseExited(with event: NSEvent) {
        self.delegate?.screenmin_mouseExited(with: event)
        super.mouseExited(with: event)
    }
}
